package com.ruoyi.healthCard.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.healthCard.domain.TPhysicalItem;
import com.ruoyi.healthCard.service.ITPhysicalItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目Controller
 * 
 * @author ruoyi
 * @date 2025-06-20
 */
@RestController
@RequestMapping("/health/item")
public class TPhysicalItemController extends BaseController
{
    @Autowired
    private ITPhysicalItemService tPhysicalItemService;

    /**
     * 查询项目列表
     */
    @PreAuthorize("@ss.hasPermi('health:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPhysicalItem tPhysicalItem)
    {
        startPage();
        List<TPhysicalItem> list = tPhysicalItemService.selectTPhysicalItemList(tPhysicalItem);
        return getDataTable(list);
    }

    /**
     * 导出项目列表
     */
    @PreAuthorize("@ss.hasPermi('health:item:export')")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPhysicalItem tPhysicalItem)
    {
        List<TPhysicalItem> list = tPhysicalItemService.selectTPhysicalItemList(tPhysicalItem);
        ExcelUtil<TPhysicalItem> util = new ExcelUtil<TPhysicalItem>(TPhysicalItem.class);
        util.exportExcel(response, list, "项目数据");
    }

    /**
     * 获取项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('health:item:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(tPhysicalItemService.selectTPhysicalItemByItemId(itemId));
    }

    /**
     * 新增项目
     */
    @PreAuthorize("@ss.hasPermi('health:item:add')")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPhysicalItem tPhysicalItem)
    {
        return toAjax(tPhysicalItemService.insertTPhysicalItem(tPhysicalItem));
    }

    /**
     * 修改项目
     */
    @PreAuthorize("@ss.hasPermi('health:item:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPhysicalItem tPhysicalItem)
    {
        return toAjax(tPhysicalItemService.updateTPhysicalItem(tPhysicalItem));
    }

    /**
     * 删除项目
     */
    @PreAuthorize("@ss.hasPermi('health:item:remove')")
    @Log(title = "项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(tPhysicalItemService.deleteTPhysicalItemByItemIds(itemIds));
    }
}
